<template>
	<el-col :xs="24" :sm="24" :md="24" :lg="24" :xl="24">
		<div class="login-home">
			<el-row :gutter="10">
				<div class="login">
					<p class="long-p">
						欢迎登录 - MMALL管理系统
					</p>
					<el-form
							:model="ruleForm"
							status-icon
							:rules="rules"
							ref="ruleForm"
							label-width="0px"
							class="demo-ruleForm"
					>
						<el-form-item  prop="pass">
							<el-input type="text" v-model="ruleForm.pass" autocomplete="off"></el-input>
						</el-form-item>
						<el-form-item  prop="checkPass">
							<el-input type="password" v-model="ruleForm.checkPass" autocomplete="off"></el-input>
						</el-form-item>
						<el-form-item>
							<el-button type="primary" @click="submitForm('ruleForm')">登录</el-button>
						</el-form-item>
					</el-form>
				</div>
			</el-row>
		</div>
	</el-col>
</template>

<script>
	import { login } from "../../http/index.js";
	export default {
		name: "Login",
		data() {
			var validatePass = (rule, value, callback) => {
				if (value === '') {
					callback(new Error('请输入用户名'));
				} else {
					if (this.ruleForm.checkPass !== '') {
						this.$refs.ruleForm.validateField('checkPass');
					}
					callback();
				}
			};
			var validatePass2 = (rule, value, callback) => {
				if (value === '') {
					callback(new Error('请输入密码'));
				} else if (value !== this.ruleForm.pass) {
					callback(new Error('密码输入错误!'));
				} else {
					callback();
				}
			};
			return {
				ruleForm: {
					pass: 'admin',
					checkPass: 'admin',
				},
				rules: {
					pass: [
						{ validator: validatePass, trigger: 'blur' }
					],
					checkPass: [
						{ validator: validatePass2, trigger: 'blur' }
					],
				},
				local:{userToken:false}
			};
		},
		methods:{
			admin(){},
			submitForm(formName) {
				this.$refs[formName].validate((valid) => {
					if (valid) {
						login({username:this.ruleForm.pass , password:this.ruleForm.checkPass}).then(data=>{
							console.log(data);
							if(data.data.status==0){
								this.$message(data.data.msg);
								localStorage.setItem("admin", this.ruleForm.pass);
								this.$router.push(
									{
										path:"/",
									})
							}else {
								this.$message(data.data.msg);
							}
						})
					} else {
						console.log('error submit!!');
						return false;
					}
				});
			},
		},
		mounted() {
			this.admin()
		},
	}
</script>

<style lang="scss" scoped>
	@import "./../../Scss/index.scss";
	.login-home{
		width: 100%;
		height: 969px;
		background-color: #ccc;
		padding-top: 246px;
		.login{
			@include SizeBack(400px,200px,#fff);
			margin: auto;
			padding: 10px;
			.long-p{
				margin-bottom: 10px;
			}
			.demo-ruleForm{
				background-color: #fff;
			}
			.el-button{
				width: 100%;
			}
			.el-button--primary{
				color: black;
				span{
					background-color: #fff;
				}
			}
			.active{
				background-color: blue;
			}
		}
	}
</style>